import { notification, message } from 'antd';
import cloneDeep from 'lodash/cloneDeep';
import _map from 'lodash/map';
import _uniq from 'lodash/uniq';
import _pull from 'lodash/pull';
import { searchCode } from '../../../services/line_service.js';

export default {
  namespace: 'kline',
  state: {
    codes: [],
  },

  effects: {
    *SearchCode({ payload, callback }, { call, put }) {
      const response = yield call(searchCode, payload);
      if (callback) callback(response);
      if (typeof response === 'undefined') {
        notification.error({
          message: typeof response.message !== 'undefined' ? response.message : '请求错误',
        });
      } else if (response.code === 1) {
        yield put({
          type: 'saveCodes',
          payload: response.data.splice(0, 6),
        });
      }
    },
  },

  reducers: {
    saveCodes(state, action) {
      return {
        ...state,
        codes: action.payload,
      };
    },
  },
};
